View Javadoc

1   // Interface.java, created Fri Apr  5 18:36:41 2002 by joewhaley
2   // Copyright (C) 2001-3 John Whaley <jwhaley@alum.mit.edu>
3   // Licensed under the terms of the GNU LGPL; see COPYING for details.
4   package joeq.ClassLib.sun15_linux;
5   
6   import java.util.Collections;
7   import java.util.Iterator;
8   import joeq.Class.PrimordialClassLoader;
9   import joeq.Class.jq_Class;
10  import joeq.Class.jq_InstanceField;
11  import joeq.Class.jq_StaticField;
12  import joeq.ClassLib.ClassLibInterface;
13  import joeq.Main.jq;
14  import joeq.Runtime.ObjectTraverser;
15  import jwutil.collections.AppendIterator;
16  
17  /*
18   * @author  John Whaley <jwhaley@alum.mit.edu>
19   * @version $Id: Interface.java 2475 2006-12-24 09:44:50Z joewhaley $
20   */
21  public class Interface extends joeq.ClassLib.sun142_linux.Interface {
22  
23      /*** Creates new Interface */
24      public Interface() {}
25  
26      public Iterator getImplementationClassDescs(joeq.UTF.Utf8 desc) {
27          if (ClassLibInterface.USE_JOEQ_CLASSLIB &&
28                  (desc.toString().startsWith("Ljava/") ||
29                   desc.toString().startsWith("Lsun/misc/"))) {
30              joeq.UTF.Utf8 u = joeq.UTF.Utf8.get("Ljoeq/ClassLib/sun15_linux/"+desc.toString().substring(1));
31              return new AppendIterator(super.getImplementationClassDescs(desc),
32                                        Collections.singleton(u).iterator());
33          }
34          return super.getImplementationClassDescs(desc);
35      }
36      
37      public ObjectTraverser getObjectTraverser() {
38          return sun15_linuxObjectTraverser.INSTANCE;
39      }
40      
41      public static class sun15_linuxObjectTraverser extends sun142_linuxObjectTraverser {
42          public static sun15_linuxObjectTraverser INSTANCE = new sun15_linuxObjectTraverser();
43          protected sun15_linuxObjectTraverser() {}
44          public void initialize() {
45              super.initialize();
46              
47              jq_Class k;
48  
49              // jdk1.5 caches name string.
50              k = (jq_Class) PrimordialClassLoader.getJavaLangClass();
51              nullInstanceFields.add(k.getOrCreateInstanceField("name", "Ljava/lang/String;"));
52              
53              // generated during reflective access.
54              k = (jq_Class) PrimordialClassLoader.loader.getOrCreateBSType("Ljava/lang/reflect/Field;");
55              nullInstanceFields.add(k.getOrCreateInstanceField("fieldAccessor", "Lsun/reflect/FieldAccessor;"));
56              nullInstanceFields.add(k.getOrCreateInstanceField("overrideFieldAccessor", "Lsun/reflect/FieldAccessor;"));
57  
58              // crashes on reflective access.
59              k = (jq_Class) PrimordialClassLoader.loader.getOrCreateBSType("Lsun/reflect/UnsafeStaticFieldAccessorImpl;");
60              nullInstanceFields.add(k.getOrCreateInstanceField("base", "Ljava/lang/Object;"));
61  
62              // zip files use mappedBuffer
63              k = (jq_Class) PrimordialClassLoader.loader.getOrCreateBSType("Ljava/util/zip/ZipFile;");
64              nullInstanceFields.add(k.getOrCreateInstanceField("mappedBuffer", "Ljava/nio/MappedByteBuffer;"));
65  
66              // leads to sun.security.rsa junk
67              k = (jq_Class)PrimordialClassLoader.loader.getOrCreateBSType("Lsun/security/jca/Providers;");
68              nullStaticFields.add(k.getOrCreateStaticField("threadLists", "Ljava/lang/ThreadLocal;"));
69              nullStaticFields.add(k.getOrCreateStaticField("providerList", "Lsun/security/jca/ProviderList;"));
70  
71              // leads to sun.security.provider.certpath junk
72              k = (jq_Class)PrimordialClassLoader.loader.getOrCreateBSType("Lsun/net/www/protocol/jar/JarFileFactory;");
73              nullStaticFields.add(k.getOrCreateStaticField("fileCache", "Ljava/util/HashMap;"));
74              nullStaticFields.add(k.getOrCreateStaticField("urlCache", "Ljava/util/HashMap;"));
75              
76              k = (jq_Class) PrimordialClassLoader.loader.getOrCreateBSType("Ljava/lang/Shutdown;");
77              nullStaticFields.add(k.getOrCreateStaticField("hooks", "Ljava/util/HashSet;"));
78  
79              k = (jq_Class) PrimordialClassLoader.loader.getOrCreateBSType("Lsun/misc/Cleaner;");
80              nullStaticFields.add(k.getOrCreateStaticField("first", "Lsun/misc/Cleaner;"));
81              nullStaticFields.add(k.getOrCreateStaticField("dummyQueue", "Ljava/lang/ref/ReferenceQueue;"));
82  
83              // Leads to an open file handle.
84              k = (jq_Class) PrimordialClassLoader.loader.getOrCreateBSType("Lsun/security/provider/NativePRNG;");
85              nullStaticFields.add(k.getOrCreateStaticField("INSTANCE", "Lsun/security/provider/NativePRNG$RandomIO;"));
86  
87              // Leads to an open file handle.
88              // TODO: needs reinit.
89              k = (jq_Class) PrimordialClassLoader.loader.getOrCreateBSType("Lsun/security/provider/SeedGenerator;");
90              nullStaticFields.add(k.getOrCreateStaticField("instance", "Lsun/security/provider/SeedGenerator;"));
91          }
92          
93          public static final jq_StaticField valueOffsetField;
94          
95          static {
96              jq_Class k = (jq_Class) PrimordialClassLoader.loader.getOrCreateBSType("Ljava/util/concurrent/atomic/AtomicLong;");
97              valueOffsetField = k.getOrCreateStaticField("valueOffset", "J");
98          }
99          
100         public java.lang.Object mapStaticField(jq_StaticField f) {
101             // valueOffset is the offset of the "value" field in AtomicLong
102             if (f == valueOffsetField) {
103                 jq_Class k = (jq_Class) PrimordialClassLoader.loader.getOrCreateBSType("Ljava/util/concurrent/atomic/AtomicLong;");
104                 k.prepare();
105                 int offset = ((jq_InstanceField) k.getDeclaredMember("value", "J")).getOffset();
106                 return new Long(offset);
107             }
108             return super.mapStaticField(f);
109         }
110     }
111 
112 }